diff options
author | 2021-09-14 09:14:39 -0400 | |
---|---|---|
committer | 2021-09-14 09:14:39 -0400 | |
commit | b6a75494b1c128503de3eba5363b46528142d8b2 (patch) | |
tree | 90098b84b352c7e60d8db4b2e18f109b6b7c6482 /examples/blog-multiple-authors/src/pages/posts/[...page].astro | |
parent | 72c916535d29fb92ab10efcf62308041ba2858a7 (diff) | |
download | astro-b6a75494b1c128503de3eba5363b46528142d8b2.tar.gz astro-b6a75494b1c128503de3eba5363b46528142d8b2.tar.zst astro-b6a75494b1c128503de3eba5363b46528142d8b2.zip |
Add types to examples and docs (#1347)
* Adds a changeset
* Add types to examples and docs
* Make changes based on review feedback
* Avoid using the variable named props
* Make path a const
Diffstat (limited to 'examples/blog-multiple-authors/src/pages/posts/[...page].astro')
-rw-r--r-- | examples/blog-multiple-authors/src/pages/posts/[...page].astro | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/examples/blog-multiple-authors/src/pages/posts/[...page].astro b/examples/blog-multiple-authors/src/pages/posts/[...page].astro index 056796deb..65b4067fc 100644 --- a/examples/blog-multiple-authors/src/pages/posts/[...page].astro +++ b/examples/blog-multiple-authors/src/pages/posts/[...page].astro @@ -10,10 +10,16 @@ let description = 'An example blog on Astro'; let canonicalURL = Astro.request.canonicalURL; // collection +interface MarkdownFrontmatter { + date: number; + description: string; + title: string; +} + import authorData from '../../data/authors.json'; export async function getStaticPaths({paginate, rss}) { - const allPosts = Astro.fetchContent('../post/*.md'); - const sortedPosts = allPosts.sort((a, b) => new Date(b.date) - new Date(a.date)); + const allPosts = Astro.fetchContent<MarkdownFrontmatter>('../post/*.md'); + const sortedPosts = allPosts.sort((a, b) => new Date(b.date).valueOf() - new Date(a.date).valueOf()); // Generate an RSS feed from this collection of posts. // NOTE: This is disabled by default, since it requires `buildOptions.site` to be set in your "astro.config.mjs" file. @@ -28,7 +34,7 @@ export async function getStaticPaths({paginate, rss}) { // pubDate: item.date, // })), // }); - + // Return a paginated collection of paths for all posts return paginate(sortedPosts, {pageSize: 1}); } @@ -43,7 +49,7 @@ const { page } = Astro.props; title={title} description={description} image={page.data[0].image} - canonicalURL={canonicalURL} + canonicalURL={canonicalURL.toString()} prev={page.url.prev} next={page.url.next} /> |